import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../controller/config_controller.dart';

class LoginPage extends StatefulWidget {
  const LoginPage({super.key});

  @override
  State<LoginPage> createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  final ConfigController _configController = Get.find<ConfigController>();

  final TextEditingController _usernameController = TextEditingController();
  final TextEditingController _passwordController = TextEditingController();

  @override
  void initState() {
    super.initState();
    final arg = Get.arguments;
    print(arg['userName']);
    print(arg['password']);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _buildBody,
    );
  }

  get _buildBody => Stack(
        children: [
          Padding(
            padding: EdgeInsets.symmetric(horizontal: 16),
            child: Column(
              children: [
                SizedBox(height: 200),
                TextField(
                  decoration: InputDecoration(
                    labelText: "username",
                    hintText: "input username",
                    hintStyle: TextStyle(
                        fontWeight: FontWeight.w300, color: Colors.red),
                    enabledBorder: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(16),
                        borderSide: BorderSide(width: 1, color: Colors.grey)),
                    focusedBorder: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(16),
                        borderSide: BorderSide(width: 1, color: Colors.black)),
                  ),
                  minLines: 1,
                  maxLines: 1,
                  cursorColor: Colors.red,
                  cursorRadius: Radius.circular(16.0),
                  cursorWidth: 16.0,
                  style: TextStyle(
                      fontSize: 14,
                      color: Colors.blue,
                      fontWeight: FontWeight.bold),
                  textAlign: TextAlign.start,
                  textInputAction: TextInputAction.next,
                  keyboardType: TextInputType.emailAddress,
                  controller: _usernameController,
                  onChanged: (v) {},
                ),
                SizedBox(height: 14),
                TextField(
                  decoration: InputDecoration(
                    labelText: "password",
                    hintText: "input password",
                    hintStyle: TextStyle(
                        fontWeight: FontWeight.w300, color: Colors.red),
                    enabledBorder: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(16),
                        borderSide: BorderSide(width: 1, color: Colors.grey)),
                    focusedBorder: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(16),
                        borderSide: BorderSide(width: 1, color: Colors.black)),
                  ),
                  minLines: 1,
                  maxLines: 1,
                  cursorColor: Colors.red,
                  cursorRadius: Radius.circular(16.0),
                  cursorWidth: 16.0,
                  style: TextStyle(
                      fontSize: 14,
                      color: Colors.blue,
                      fontWeight: FontWeight.bold),
                  textAlign: TextAlign.start,
                  textInputAction: TextInputAction.done,
                  keyboardType: TextInputType.visiblePassword,
                  controller: _passwordController,
                  onChanged: (v) {},
                ),
                SizedBox(height: 14),
                Row(
                  children: [
                    Expanded(
                        child: FilledButton(
                      onPressed: () {
                        if (_usernameController.text.isNotEmpty &&
                            _passwordController.text.isNotEmpty) {
                          _configController.isLogin.value = true;
                        }
                      },
                      style: ButtonStyle(
                        backgroundColor:
                            WidgetStatePropertyAll(Colors.blueAccent),
                        overlayColor: WidgetStatePropertyAll(
                            Colors.blue.withOpacity(0.5)),
                      ),
                      child: Text("Sign in"),
                    ))
                  ],
                )
              ],
            ),
          ),
          Center(
            child: Text("Login${_configController.appVersion}"),
          )
        ],
      );
}
